﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<fmt:setBundle basename="ApplicationMessage" />
<fmt:setLocale value="zh_CN" />

<div class="modal-dialog x-modal-dialog" style="width:800px;">

  <div class="modal-content">

    <div class="modal-header x-breadcrumb no-bottom-border clearfix">

      <h2><i class="glyphicon glyphicon-fire"></i>&nbsp;&nbsp;<span>编辑产品&nbsp;-&nbsp;基本信息</span></h2>

      <button type="button" class="close" data-dismiss="modal">&times;</button>

    </div>

    <form class="form-horizontal" method="POST" action="${ctx.host}/credit-products/${product.id}" data-validate="true">
    
      <input type="hidden" name="_method" value="PATCH">
      <input type="hidden" name="productId" value="${product.id}">
      
      <div class="modal-body">
      	
      	<div class="form-group x-form-group">
     		<label class="col-xs-2 control-label">产品名称</label>
         	<div class="pull-left col-xs-4" style="width: 30%;">
         	  <input type="text" class="form-control" name="name" value="${product.name}" data-validate="required" />
         	</div>
         	<label class="col-xs-2 control-label">产品标签</label>
	          <div class="pull-left col-xs-4" style="width: 30%;">
	            <select name="inputTags" class="form-control" multiple  data-validate="required">
	              <option value=""></option>
	              <c:forEach var="productTag" items="${enums['creditProductTag']}">
	                   <c:choose>
                		  <c:when test="${fn:containsIgnoreCase(product.tags,productTag.alias)}">
              			      <option value="${productTag}" selected>${productTag.description}</option>
             		     </c:when>
             		     <c:otherwise>
                  		  <option value="${productTag}">${productTag.description}</option>
                		  </c:otherwise>
               		 </c:choose>
	              </c:forEach>
	            </select>
	          </div>
      	</div>
      	<div class="form-group x-form-group">
   		<label class="control-label col-xs-2">创建时间 </label>
        <div class="col-xs-4 pull-left">
          <p class="form-control-static">
           <fmt:formatDate value="${product.createTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
          </p>
        </div>
        <c:if test="${product.type.coupon}">
           <label class="control-label col-xs-2">所属优惠券批次 </label>
            <div class="col-xs-4 pull-left">
               <p class="form-control-static">
                  ${persist.getCreditCouponBatch(product.creditCouponBatchId).name}
               </p>
            </div>
        </c:if>    
      	</div>
      	
        <div class="form-group x-form-group">
          <c:if test="${product.type.coupon}">
          	<label class="col-xs-2 control-label">产品原价</label>
	          <div class="pull-left col-xs-4" style="width: 30%;">
	             <p class="form-control-static">${product.price}</p>
	          </div>
          </c:if>
          <c:if test="${product.type.product}">
	          <label class="col-xs-2 control-label">产品原价</label>
	          <div class="pull-left col-xs-4" style="width: 30%;">
	            <input type="text" class="form-control" name="price" value="${product.price}" data-validate="required|float" />
	          </div>
          </c:if>
          
          <label class="col-xs-2 control-label">产品现价</label>
          <div class="pull-left col-xs-4" style="width: 30%;">
            <input type="text" class="form-control" name="currentPrice" value="${product.currentPrice}" data-validate="required|float" />
          </div>
          
        </div>
        <div class="form-group x-form-group">
          <label class="col-xs-2 control-label">产品简介</label>
          <div class="pull-left col-xs-9" style="width: 77%;">
            <textarea name="summary" rows="5" style="width: 100%;" data-validate="required">${product.summary}</textarea>
          </div>
        </div>
        
      </div>

      <div class="modal-footer">
        <button type="submit" class="btn btn-success btn-shadow btn-shadow-success x-btn">确定</button>&nbsp;&nbsp;&nbsp;&nbsp;
        <button type="button" class="btn btn-default btn-shadow btn-shadow-default x-btn" data-dismiss="modal">取消</button>
      </div>
    </form>

  </div>

</div>

<script>
$(document).ready(function(){
  
  $('select[name="inputTags"]').select2({
    placeholder : '请选择产品标签',
    minimumResultsForSearch : 5,
    allowClear : true,
  });
  
});
</script>